from common import *

import numpy
default_data = 1

def setup(data = default_data):
    import wx
    dlg = wx.TextEntryDialog(
        None, 'Number of stumps',
        'Configure Process', str(data))
    if dlg.ShowModal() == wx.ID_OK:
        data = int(dlg.GetValue())
    dlg.Destroy()
    return data

def PartitionRangeParamFunc(in0,out0 , data = default_data):
    stump_count = data

    while True:
        (start,end,size) = in0()

        stump_size = int(float(size)/float(stump_count))
        extra = size - stump_count*stump_size

        stumps = []

        offset_stump_size = (end-start)/float(stump_count)
        offset = start

        for i in range(data):
            if extra > 0:
                stump = (offset, offset+offset_stump_size, stump_size + 1)
                extra -= 1
            elif extra < 0:
                stump = (offset, offset+offset_stump_size, stump_size - 1)
                extra += 1
            else:
                stump = (offset, offset+offset_stump_size, stump_size)
            stumps.append(stump)

            # Next offset
            offset = offset+offset_stump_size
        
        job_id = 1
        for stump in stumps:
            out0((job_id,stump))
            job_id += 1

